#include "Ship.h"


CShip::CShip(void)
{
	m_nStat_Turning=0;
	m_nStat_Mass=0;
	m_nStat_FuelConsumption=0;
	m_nStat_HullPointz=0;
	m_nStat_SensorPackage=0;
	m_nStat_Thrusters=0;
	Zero_Special();
	for(int i = 0; i < 3; i++)
	{
		m_cParts[i] = CPart(0,0,0,0,0,0,0,0,0,HTexture());
	}
	bool test= CalcutateStats();
	//(if test Equal True;
}


CShip::~CShip(void)
{
}

void CShip::Set_Special(bool OnOff, unsigned int ability)
{
	if(OnOff==true)
	{
		m_unSpecialbit|= (1<<ability);
	}
	if(OnOff==false)
	{
		m_unSpecialbit&=~(1<<ability);
	}
}

bool CShip::CalcutateStats(void)
{
	//Use the Parts to set up the stats of the ships;	
	m_nStat_Turning			=m_cParts[0].Get_Part_Turning()			+m_cParts[1].Get_Part_Turning()			+m_cParts[2].Get_Part_Turning();
	
	m_nStat_Mass				=m_cParts[0].Get_Part_Mass()				+m_cParts[1].Get_Part_Mass()				+m_cParts[2].Get_Part_Mass();
	
	m_nStat_FuelConsumption	=m_cParts[0].Get_Part_FuelConsumption()	+m_cParts[1].Get_Part_FuelConsumption()	+m_cParts[2].Get_Part_FuelConsumption();
	
	m_nStat_HullPointz		=m_cParts[0].Get_Part_HullPointz()			+m_cParts[1].Get_Part_HullPointz()			+m_cParts[2].Get_Part_HullPointz();
	
	m_nStat_SensorPackage		=m_cParts[0].Get_Part_SensorPackage()		+m_cParts[1].Get_Part_SensorPackage()		+m_cParts[2].Get_Part_SensorPackage();
	
	m_nStat_Thrusters			=m_cParts[0].Get_Part_Thrusters()			+m_cParts[1].Get_Part_Thrusters()			+m_cParts[2].Get_Part_Thrusters();
	//
	//in an effort to to screw the Player (and keep things easier), All stats CANNOT be negitive, and There is always at least One point for the hull;
	if(m_nStat_Turning<0)
		m_nStat_Turning=0;
	
	if(m_nStat_Mass<0)
		m_nStat_Mass=0;
	
	if(m_nStat_FuelConsumption<0)
		m_nStat_FuelConsumption=0;
	
	if(m_nStat_HullPointz<1)
		m_nStat_HullPointz=1;
	
	m_nHP=m_nStat_HullPointz;
	
	if(m_nStat_SensorPackage<0)
		m_nStat_SensorPackage=0;
	
	if (m_nStat_Thrusters<0)
		m_nStat_Thrusters=0;
	
	//Ok, now The Special
	//Check to see if the three Part have been set
	//									\/this means it hasn't been set(should never be zero)
	if (m_cParts[0].Get_Part_Title() != CPart::P_NA)
	{
		//if the nose and the hull are from the same ship
		if (m_cParts[0].Get_Part_Title()==m_cParts[1].Get_Part_Title())
		{
			//if the hull and engine are from the same ship
			if (m_cParts[1].Get_Part_Title()== m_cParts[2].Get_Part_Title())
			{
				//you have three matching Part
				Set_Special(true,m_cParts[0].Get_Part_Special());
				return true;
			}
		}
		return false;
	}

	return false; //everthing worked
}

void CShip::Set_Part(unsigned int unPart_Type, unsigned int unPart_Title, unsigned int unPart_Special,  int nStat_Turning,int nStat_Mass,int nStat_FuelConsumption,
			int nStat_HullPointz,	int nStat_SensorPackage, int nStat_Thrusters, HTexture unShip_Part_Image)
{

	 CPart d(unPart_Title,unPart_Special, unPart_Type, nStat_Turning, nStat_Mass, nStat_FuelConsumption,
										nStat_HullPointz, nStat_SensorPackage, nStat_Thrusters,unShip_Part_Image);
		m_cParts[unPart_Type]=d;
}

void CShip::DamageShip(int namount)
{

	Set_HP(Get_HP()-namount);

	if (Get_HP() ==0)
	{
		// ship's dead
	}


}

CPart CShip::Get_Part(unsigned int Part_Type)
{
	return m_cParts[Part_Type];
}